Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ConfigureHostOptions implemetation #49502

Closed
wants to merge 4 commits into from
Closed

Conversation

I-SER-I
Copy link
Contributor

@I-SER-I I-SER-I commented Mar 11, 2021

close #48743

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Mar 11, 2021

Tagging subscribers to this area: @eerhardt, @maryamariyan
See info in area-owners.md if you want to be subscribed.

Issue Details
Author: I-SER-I
Assignees: -
Labels:

area-Extensions-Hosting, new-api-needs-documentation

Milestone: -

Copy link
Member

@maryamariyan maryamariyan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @I-SER-I , could you please add tests for the new API under src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostBuilderTests.cs?

/// <returns>The same instance of the <see cref="IHostBuilder"/> for chaining.</returns>
public static IHostBuilder ConfigureHostOptions(this IHostBuilder hostBuilder, Action<HostOptions> configureDelegate)
{
return hostBuilder.ConfigureServices((context, collection) => collection.Configure(configureDelegate));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you could be using the other overload here for simplicity, since no context is passed around

Suggested change
return hostBuilder.ConfigureServices((context, collection) => collection.Configure(configureDelegate));
return hostBuilder.ConfigureServices(collection => collection.Configure(configureDelegate));

@@ -42,6 +42,7 @@ public static partial class HostingHostBuilderExtensions
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureLogging(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Hosting.HostBuilderContext, Microsoft.Extensions.Logging.ILoggingBuilder> configureLogging) { throw null; }
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureLogging(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Logging.ILoggingBuilder> configureLogging) { throw null; }
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureServices(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> configureDelegate) { throw null; }
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureHostOptions(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Hosting.HostOptions> configureDelegate) { throw null; }
Copy link
Member

@maryamariyan maryamariyan Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to how we have two ConfigureLogging overloads:

public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureLogging(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Hosting.HostBuilderContext, Microsoft.Extensions.Logging.ILoggingBuilder> configureLogging) { throw null; }
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureLogging(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Logging.ILoggingBuilder> configureLogging) { throw null; }

ConfigureHostOptions could have another overload as well with the following signature:

Suggested change
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureHostOptions(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Hosting.HostOptions> configureDelegate) { throw null; }
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureHostOptions(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Hosting.HostBuilderContext, Microsoft.Extensions.Hosting.HostOptions> configureOptions) { throw null; }
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureHostOptions(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Hosting.HostOptions> configureOptions) { throw null; }

@eerhardt
Copy link
Member

@I-SER-I - Thanks for your help here. Are you interested in progressing this PR? If not, we can get someone else to take it forward.

@I-SER-I
Copy link
Contributor Author

I-SER-I commented Apr 16, 2021

@eerhardt Sorry for the delay). I'll do it this week

@IEvangelist
Copy link
Member

@eerhardt Eric Erhardt FTE Sorry for the delay). I'll do it this week

Hi @I-SER-I - I put together a PR #51410 that would close this one. I didn't realize that you were still working on this.

@I-SER-I
Copy link
Contributor Author

I-SER-I commented Apr 16, 2021

@eerhardt Eric Erhardt FTE Sorry for the delay). I'll do it this week

Hi @I-SER-I - I put together a PR #51410 that would close this one. I didn't realize that you were still working on this.

No problem)

@IEvangelist
Copy link
Member

@eerhardt

        Eric Erhardt
        FTE Eric Erhardt FTE Sorry for the delay). I'll do it this week

Hi @I-SER-I - I put together a PR #51410 that would close this one. I didn't realize that you were still working on this.

No problem)

Hey @I-SER-I - I think we should fix the merge conflicts in this PR, and update it with a few suggestions. Similar to what was done #51410. What do you say?

Copy link
Member

@IEvangelist IEvangelist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +137 to +147
/// <summary>
/// Adds a delegate for configuring the host settings. This can be called multiple times and
/// the results will be additive.
/// </summary>
/// <param name="hostBuilder">The <see cref="IHostBuilder"/> to configure.</param>
/// <param name="configureDelegate">The delegate for the <see cref="HostOptions"/>.</param>
/// <returns>The same instance of the <see cref="IHostBuilder"/> for chaining.</returns>
public static IHostBuilder ConfigureHostOptions(this IHostBuilder hostBuilder, Action<HostOptions> configureDelegate)
{
return hostBuilder.ConfigureServices((context, collection) => collection.Configure(configureDelegate));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// <summary>
/// Adds a delegate for configuring the host settings. This can be called multiple times and
/// the results will be additive.
/// </summary>
/// <param name="hostBuilder">The <see cref="IHostBuilder"/> to configure.</param>
/// <param name="configureDelegate">The delegate for the <see cref="HostOptions"/>.</param>
/// <returns>The same instance of the <see cref="IHostBuilder"/> for chaining.</returns>
public static IHostBuilder ConfigureHostOptions(this IHostBuilder hostBuilder, Action<HostOptions> configureDelegate)
{
return hostBuilder.ConfigureServices((context, collection) => collection.Configure(configureDelegate));
}
/// <summary>
/// Adds a delegate for configuring the <see cref="HostOptions"/> of the <see cref="IHost"/>.
/// </summary>
/// <param name="hostBuilder">The <see cref="IHostBuilder" /> to configure.</param>
/// <param name="configureOptions">The delegate for configuring the <see cref="HostOptions"/>.</param>
/// <returns>The same instance of the <see cref="IHostBuilder"/> for chaining.</returns>
public static IHostBuilder ConfigureHostOptions(this IHostBuilder hostBuilder, Action<HostBuilderContext, HostOptions> configureOptions)
{
return hostBuilder.ConfigureServices(
(context, collection) => collection.Configure<HostOptions>(options => configureOptions(context, options)));
}
/// <summary>
/// Adds a delegate for configuring the <see cref="HostOptions"/> of the <see cref="IHost"/> instance
/// related to th.
/// </summary>
/// <param name="hostBuilder">The <see cref="IHostBuilder" /> to configure.</param>
/// <param name="configureOptions">The delegate for configuring the <see cref="HostOptions"/>.</param>
/// <returns>The same instance of the <see cref="IHostBuilder"/> for chaining.</returns>
public static IHostBuilder ConfigureHostOptions(this IHostBuilder hostBuilder, Action<HostOptions> configureOptions)
{
return hostBuilder.ConfigureServices(collection => collection.Configure(configureOptions));
}

@eerhardt
Copy link
Member

Superseded by #51410.

Thanks for the contribution here @I-SER-I.

@ghost ghost locked as resolved and limited conversation to collaborators May 19, 2021
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add API to make configuring the HostOptions easier
6 participants